package org.example;

import org.openjdk.jol.info.ClassLayout;

public class Main3 {

    public static void main(String[] args) {
        //===================开启指针压缩的结果
        //Klass是64bits(8个字节)但是这儿只有4个字节，是因为我们开启了指针压缩
        A a = new A();
        System.out.println(ClassLayout.parseInstance(a).toPrintable());//有对齐填充
        /*
        org.example.A object internals:
         OFFSET  SIZE      TYPE DESCRIPTION                               VALUE
              0     4           (object header)                           05 00 00 00 (00000101 00000000 00000000 00000000) (5)
              4     4           (object header)                           00 00 00 00 (00000000 00000000 00000000 00000000) (0)
              8     4           (object header)                           48 72 06 00 (01001000 01110010 00000110 00000000) (422472)
             12     1   boolean A.flag                                    false
             13     3           (loss due to the next object alignment)
        Instance size: 16 bytes
        Space losses: 0 bytes internal + 3 bytes external = 3 bytes total
         */

        B b = new B();
        System.out.println(ClassLayout.parseInstance(b).toPrintable());//没有对齐填充
        /*
        org.example.B object internals:
         OFFSET  SIZE   TYPE DESCRIPTION                               VALUE
              0     4        (object header)                           05 00 00 00 (00000101 00000000 00000000 00000000) (5)
              4     4        (object header)                           00 00 00 00 (00000000 00000000 00000000 00000000) (0)
              8     4        (object header)                           e0 f2 0e 00 (11100000 11110010 00001110 00000000) (979680)
             12     4    int B.count                                   0
        Instance size: 16 bytes
        Space losses: 0 bytes internal + 0 bytes external = 0 bytes total
         */


        C c = new C();
        System.out.println(ClassLayout.parseInstance(c).toPrintable());//没有实例数据
        /*
        org.example.C object internals:
         OFFSET  SIZE   TYPE DESCRIPTION                               VALUE
              0     4        (object header)                           05 00 00 00 (00000101 00000000 00000000 00000000) (5)
              4     4        (object header)                           00 00 00 00 (00000000 00000000 00000000 00000000) (0)
              8     4        (object header)                           e8 74 0e 00 (11101000 01110100 00001110 00000000) (947432)
             12     4        (loss due to the next object alignment)
        Instance size: 16 bytes
        Space losses: 0 bytes internal + 4 bytes external = 4 bytes total


        Process finished with exit code 0
         */



        //============关闭指针压缩的结果 -XX:-UseCompressedOops

        /*
        org.example.A object internals:
         OFFSET  SIZE      TYPE DESCRIPTION                               VALUE
              0     4           (object header)                           05 00 00 00 (00000101 00000000 00000000 00000000) (5)
              4     4           (object header)                           00 00 00 00 (00000000 00000000 00000000 00000000) (0)
              8     4           (object header)                           90 5c f1 e9 (10010000 01011100 11110001 11101001) (-370058096)
             12     4           (object header)                           f6 01 00 00 (11110110 00000001 00000000 00000000) (502)
             16     1   boolean A.flag                                    false
             17     7           (loss due to the next object alignment)
        Instance size: 24 bytes
        Space losses: 0 bytes internal + 7 bytes external = 7 bytes total

        org.example.B object internals:
         OFFSET  SIZE   TYPE DESCRIPTION                               VALUE
              0     4        (object header)                           05 00 00 00 (00000101 00000000 00000000 00000000) (5)
              4     4        (object header)                           00 00 00 00 (00000000 00000000 00000000 00000000) (0)
              8     4        (object header)                           a0 df 5a eb (10100000 11011111 01011010 11101011) (-346366048)
             12     4        (object header)                           f6 01 00 00 (11110110 00000001 00000000 00000000) (502)
             16     4    int B.count                                   0
             20     4        (loss due to the next object alignment)
        Instance size: 24 bytes
        Space losses: 0 bytes internal + 4 bytes external = 4 bytes total

        org.example.C object internals:
         OFFSET  SIZE   TYPE DESCRIPTION                               VALUE
              0     4        (object header)                           05 00 00 00 (00000101 00000000 00000000 00000000) (5)
              4     4        (object header)                           00 00 00 00 (00000000 00000000 00000000 00000000) (0)
              8     4        (object header)                           00 e4 5a eb (00000000 11100100 01011010 11101011) (-346364928)
             12     4        (object header)                           f6 01 00 00 (11110110 00000001 00000000 00000000) (502)
        Instance size: 16 bytes
        Space losses: 0 bytes internal + 0 bytes external = 0 bytes total


        Process finished with exit code 0


         */

    }
}

class A {
    private boolean flag;
}

class B {
    private int count;
}

class C {

}